package cn.yzstu;

/**
 * @author Baldwin
 */
public class CloneTest implements Cloneable {


    private static CloneTest baseCloneTest = new CloneTest();

    public static CloneTest getInstance() throws CloneNotSupportedException {
        return (CloneTest) baseCloneTest.clone();
    }

    public static void main(String[] args) {

        new Thread(new Runnable() {
            private long startTime;
            private long endTime;

            @Override
            public void run() {
                startTime = System.nanoTime();
                try {
                    for (int i = 0; i < 100; i++) {

                        CloneTest cloneTest = CloneTest.getInstance();

                    }
                } catch (CloneNotSupportedException e) {
                    e.printStackTrace();
                }
                endTime = System.nanoTime();
                System.out.println("clone:" + (endTime - startTime));
            }
        }).start();

        new Thread(new Runnable() {
            private long startTime;
            private long endTime;

            @Override
            public void run() {
                startTime = System.nanoTime();
                for (int i = 0; i < 100; i++) {
                    CloneTest cloneTest = new CloneTest();
                }
                endTime = System.nanoTime();
                System.out.println("new:" + (endTime - startTime));
            }
        }).start();


    }
}
